# -*- coding: utf-8 -*-
# @project: huawang-api20230914
# @file： yk_mainPage.py
# @Time：2023/9/8 09:38
# @Author：liaogan
import time

from common.commin.basePage import BasePage
from po.yk.ht.ProductManagrmentpage import ProductClassification, Specification, FreightTemplate
from po.yk.ht.MemberManagepage import MemberList, MemberGrade

from common.log.log import log
from po.yk.ht.StoreManagePage import StoreList


class MainPage(BasePage):
    """
    功能
        1. 跳转到添加商品页
        2. 跳转到商品列表页
    """

    # 去商品分类页面
    def goto_ProductClassification(self):
        """去商品分类页面"""
        # self.click_element(self.product_manage, desc='点击商品管理菜单')
        # self.click_element(self.product_sort, desc='点击商品分类table')
        # return ProductClassification()  # 返回商品分类页面
        sel = self.get_elelment(self.product_manage)
        open_or_not = sel.get_attribute('class')  # “用户” 菜单是否展开
        log.info(f'点击之前的class属性{sel.get_attribute("class")}')
        if 'is-opened' not in open_or_not:
            sel.click()
            log.info(f'点击之前的class属性{sel.get_attribute("class")}')
        self.click_element(self.product_sort, desc='点击商品分类table')
        time.sleep(2)
        return ProductClassification()  # 返回商品分类页面

    def goto_Specification(self):
        """去商品规格页面"""
        sel = self.get_elelment(self.product_manage)
        open_or_not = sel.get_attribute('class')  # “用户” 菜单是否展开
        log.info(f'点击之前的class属性{sel.get_attribute("class")}')
        if 'is-opened' not in open_or_not:
            sel.click()
            log.info(f'点击之前的class属性{sel.get_attribute("class")}')
        self.click_element(self.submenu_productnuit, desc='点击商品规格table')
        time.sleep(2)
        return Specification()  # 返回到商品规格页面

    def goto_FreightTemplate(self):
        """去运费模版页面"""
        # 获取元素属性
        sel = self.get_elelment(self.product_manage, desc='获取商品管理属性')
        open_or_not = sel.get_attribute('class')
        log.info(f'点击之前的class属性{sel.get_attribute("class")}')
        if 'is-opend' not in open_or_not:
            sel.click()
            log.info(f'点击之后的class属性{sel.get_attribute("class")}')
        self.click_element(self.submenu_Freight_template, desc='点击商品运费模版')
        time.sleep(2)
        return FreightTemplate()

    def goto_Memberlist(self):
        """会员列表页面"""
        # 获取元素属性
        sel = self.get_elelment(self.member_manage, desc='获取会员管理属性')
        open_or_not = sel.get_attribute('class')
        log.info(f'点击之前的class属性{sel.get_attribute("class")}')
        if 'is-opend' not in open_or_not:
            sel.click()
            log.info(f'点击之后的class属性{sel.get_attribute("class")}')
        self.click_element(self.submenu_memberlist, desc='点击会员列表页面')
        time.sleep(3)
        return MemberList()

    def goto_Membergrade(self):
        """去会员等级页面"""
        sel = self.get_elelment(self.member_manage)
        open_or_not = sel.get_attribute('class')  # “用户” 菜单是否展开
        log.info(f'点击之前的class属性{sel.get_attribute("class")}')
        if 'is-opened' not in open_or_not:
            sel.click()
            log.info(f'点击之后的class属性{sel.get_attribute("class")}')
        self.click_element(self.sunmenu_grade, desc='点击会员等级页面')
        time.sleep(2)
        return MemberGrade()  # 返回会员列表子菜单

    def goto_StoreList(self):
        """去会员等级页面"""
        sel = self.get_elelment(self.store_manage, desc="回去门店管理属性值")
        open_or_not = sel.get_attribute('class')  # “用户” 菜单是否展开
        log.info(f'点击之前的class属性{sel.get_attribute("class")}')
        if 'is-opened' not in open_or_not:
            sel.click()
            log.info(f'点击之后的class属性{sel.get_attribute("class")}')
        self.click_element(self.sunmenu_storelist, desc='点击门店列表子菜单')
        time.sleep(2)
        return StoreList()  # 返回会员列表子菜单

    def goto_ManagerpageProduct(self):
        """去到会员等级子页面"""
        sel = self.get_elelment(self.product_manage)
        open_or_not = sel.get_attribute('class')  # “用户” 菜单是否展开
        log.info(f'点击之前的class属性{sel.get_attribute("class")}')
        if 'is-opened' not in open_or_not:
            sel.click()
            log.info(f'点击之后的class属性{sel.get_attribute("class")}')
        self.click_element(self.sunmenu_grade)
        time.sleep(2)
        return MemberGrade()  # 返回会员等级子菜单
